package com.hsy.linemoney.apiservice;

import com.deparse.dpframe.tools.utils.DPGsonUtil;
import com.hsy.linemoney.R;
import com.hsy.linemoney.requests.RequestTask;
import com.hsy.linemoney.utils.ToastUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2016/12/23.
 */

public class IsTermsOfUseCompleteService extends BasicService<JSONArray> {
    public void getIsUseComplete(String email, final Callback<UseCompleteGson> callback, boolean... clearData) {
//        String api = "/LmBusinessServices-portlet.order/user/newOrders";
        String api = "/LmRegistration-portlet.account/isTermsOfUseComplete";
        JSONObject params = ParamsMaker.newInstance()
                .add("companyId", 20155)
                .add("emailAddress", email)
                .get();

        invoke(0, api, params, new Callback<JSONArray>() {
            @Override
            public void onSuccess(int what, JSONArray result) {

                try {
                    if (null != callback) {
                        callback.onSuccess(0, DPGsonUtil.fromJson(result.get(0).toString(), UseCompleteGson.class));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    callback.onError(what, 0, e.getLocalizedMessage(), e);
                }
            }

            @Override
            public void onError(int what, int type, String msg, Exception e) {
                if (e instanceof RequestTask.StatusCodeException) {
                    ToastUtil.showToast(msg);
                } else {
                    ToastUtil.showToast(R.string.txt_network_failure);
                }
                if (null != callback) {
                    callback.onError(what, 0, msg, e);
                }
            }
        });
    }

    public class UseCompleteGson {
        private Status status;

        private Value value;

        public void setStatus(Status status) {
            this.status = status;
        }

        public Status getStatus() {
            return this.status;
        }

        public void setValue(Value value) {
            this.value = value;
        }

        public Value getValue() {
            return this.value;
        }

        public class Status {
            private String message;

            private int code;

            public void setMessage(String message) {
                this.message = message;
            }

            public String getMessage() {
                return this.message;
            }

            public void setCode(int code) {
                this.code = code;
            }

            public int getCode() {
                return this.code;
            }

        }

        public class Value {
            private boolean isTermsOfUseAgreed;

            public void setIsTermsOfUseAgreed(boolean isTermsOfUseAgreed) {
                this.isTermsOfUseAgreed = isTermsOfUseAgreed;
            }

            public boolean getIsTermsOfUseAgreed() {
                return this.isTermsOfUseAgreed;
            }

        }


    }
}
